package com.yuexiang.melodyhub.common.utils;

import org.springframework.security.crypto.bcrypt.BCrypt;

public class PasswordUtil {
    public static String hashPassword(String plainPassword) {
        return BCrypt.hashpw(plainPassword, BCrypt.gensalt());
    }

    public static boolean checkPassword(String plainPassword, String hashedPassword) {
        return BCrypt.checkpw(plainPassword, hashedPassword);
    }

    public static boolean validatePassword(String password) {
        String regx = "^(?=.*\\d)(?=.*[a-zA-Z])(?=.*[~!@#$%^&*.])[\\da-zA-Z~!@#$%^&*.]{8,}$";
        return password != null && password.matches(regx);
    }
}
